﻿namespace A1;

public class GenericList<T>
{
    private Node<T> head;
    
    private Node<T> tail;
    
    public GenericList()
    {
        head = tail = null;
    }
    
    public Node<T> Head => head;
    
    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if (tail == null)
        {
            head = tail = n;
        }
        else
        {
            tail.Next = n;
            tail = n;
        }
    }
    
    public void ForEach(Action<T> action)
    {
        Node<T> current = head;
        while (current != null)
        {
            action(current.Data);
            current = current.Next;
        }
    }
}